package cn.lds.health.controller;

import cn.lds.health.dto.ResultDTO;
import cn.lds.health.entity.HealthExamItem;
import cn.lds.health.entity.User;
import cn.lds.health.exception.SysException;
import cn.lds.health.service.HealthExamItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @ClassName HealthExamItemController
 * @Description TODO
 * @Author Christopher
 * @Date 2023/8/8 16:12
 * @Version 1.0
 **/

@Controller
@RequestMapping("/health_exam_item")
public class HealthExamItemController {
	
	@Autowired
	private HealthExamItemService healthExamItemService;
	
	/**
	 * 跳转到新增体检项目页面
	 * @return
	 */
	@RequestMapping("/add_health_item")
	public String addHealthItem(){
		return "add_health_item";
	}
	
	/**
	 * 接收表单提交内容
	 * @param healthExamItem
	 * @param session
	 * @param model
	 * @return
	 * @throws SysException
	 */
	@RequestMapping("/do_add_health_item")
	public String doAddHealthItem(HealthExamItem healthExamItem, HttpSession session, Model model) throws SysException {
		User loginUser = (User) session.getAttribute("user");
		healthExamItem.setCreateBy(loginUser.getId());
		ResultDTO resultDTO = healthExamItemService.addHealthExamItem(healthExamItem);
		model.addAttribute("result",resultDTO);
		
		return "add_success";
		
	}
	
	
}